package com.example.job_listener;

import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;
import org.springframework.batch.core.annotation.AfterJob;
import org.springframework.batch.core.annotation.BeforeJob;
import org.springframework.stereotype.Component;

/**
 * 使用注解的方式实现监听器
 * 作业监听器
 */
@Component(value = "myAnnJobStateListener")
public class JobAnnStateListener  {
    /**
     * 作业执行前
     * @param jobExecution the current {@link JobExecution}
     */
    @BeforeJob
    public void beforeJob(JobExecution jobExecution) {
        System.err.println("作业执行前 status = " + jobExecution.getStatus());
    }

    /**
     * 作业执行后
     * @param jobExecution the current {@link JobExecution}
     */
    @AfterJob
    public void afterJob(JobExecution jobExecution) {
        System.err.println("作业执行后 status = " + jobExecution.getStatus());

    }
}
